\documentclass[12pt]{article}
\usepackage{times}
\usepackage{graphicx}
\usepackage{sidecap}
\usepackage{wrapfig}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\baselinestretch}{1.2}
\newenvironment{mylisting}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\newenvironment{mylisting2}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}

%%% This file is Open Content

\begin{document}
	\textbf{{\Huge Python 3D engine}}
{\center{Dec 29, 2011, 
	Johan Ceuppens, Theo D'Hondt - Vrije Universiteit Brussel}}
\\
{\large{\textbf{\center Abstract}}}
\\
\\
\section{\large Introduction}



\begin{mylisting}
\begin{verbatim}

	
### 3d.engine
###
### Copyright (c) 2011-2012 Johan Ceuppens
###
### All rights reserved.
###
### Redistribution and use in source and binary forms, with or without
### modification, are permitted provided that the following conditions
### are met:
### 1. Redistributions of source code must retain the above copyright
###    notice, this list of conditions and the following disclaimer.
### 2. Redistributions in binary form must reproduce the above copyright
###    notice, this list of conditions and the following disclaimer in the
###    documentation and/or other materials provided with the distribution.
### 3. The name of the authors may not be used to endorse or promote products
###    derived from this software without specific prior written permission.
###
### THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
### IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
### OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
### IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
### INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
### NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
### DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
### THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
### (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
### THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Copyright (C) Johan Ceuppens 2011-2012

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import pygame, sys,os
from pygame.locals import *

from vector3 import *

class Cube():
    def __init__(self, tx,ty,tz):

	self.tx = tx
	self.ty = ty
	self.tz = tz

   	### backside square
	self.v11 = Vector3(10.0+self.tx,10.0+self.ty,0.0+self.tz)
        self.v12 = Vector3(20.0+self.tx,10.0+self.ty,0.0+self.tz)
        self.v13 = Vector3(20.0+self.tx,20.0+self.ty,0.0+self.tz)
        self.v14 = Vector3(10.0+self.tx,20.0+self.ty,0.0+self.tz)
	### front side square
        self.v21 = Vector3(10.0+10.0+self.tx,10.0+5.0+self.ty,5.0+self.tz) ## NOTE z
        self.v22 = Vector3(20.0+10.0+self.tx,10.0+5.0+self.ty,5.0+self.tz)
        self.v23 = Vector3(20.0+10.0+self.tx,20.0+5.0+self.ty,5.0+self.tz)
        self.v24 = Vector3(10.0+10.0+self.tx,20.0+5.0+self.ty,5.0+self.tz)
	### connections
        self.vconn1 = Vector3(10.0+self.tx,10.0+self.ty,0.0+self.tz)
        self.vconn2 = Vector3(10.0+10.0+self.tx,10.0+5.0+self.ty,5.0+self.tz)

        self.vconn3 = Vector3(20.0+self.tx,10.0+self.ty,0.0+self.tz)
        self.vconn4 = Vector3(20.0+10.0+self.tx,10.0+5.0+self.ty,5.0+self.tz)
   
	self.vconn5 = Vector3(20.0+self.tx,20.0+self.ty,0.0+self.tz)
	self.vconn6 = Vector3(20.0+10.0+self.tx,20.0+5.0+self.ty,5.0+self.tz)

	self.vconn7 = Vector3(10.0+self.tx,20.0+self.ty,0.0+self.tz)
	self.vconn8 = Vector3(10.0+10.0+self.tx,20.0+5.0+self.ty,5.0+self.tz)

    def transpose(self):
	1

    def rotate(self,engine,rx,ry,rz):
	### FIXME : reset engine's matrices mx etc. are held
	engine.rotate(rx,ry,rz)
    	self.v11 = engine.transmit(self.engine.mx,self.engine.my)

    	self.v12 = engine.transmit(self.engine.mx,self.engine.my)
    	self.v13 = engine.transmit(self.engine.mx,self.engine.my)
    	self.v14 = engine.transmit(self.engine.mx,self.engine.my)
    	self.vconn1 = engine.transmit(self.engine.mx,self.engine.my)
    	self.vconn2 = engine.transmit(self.engine.mx,self.engine.my)
    	self.vconn3 = engine.transmit(self.engine.mx,self.engine.my)
    	self.vconn4 = engine.transmit(self.engine.mx,self.engine.my)
    	self.vconn5 = engine.transmit(self.engine.mx,self.engine.my)
    	self.vconn6 = engine.transmit(self.engine.mx,self.engine.my)
    	self.vconn7 = engine.transmit(self.engine.mx,self.engine.my)
    	self.vconn8 = engine.transmit(self.engine.mx,self.engine.my)



    def display(self, engine):
    	engine.display(self.v11,self.v12)
    	engine.display(self.v12,self.v13)
    	engine.display(self.v13,self.v14)
    	engine.display(self.v14,self.v11)
    	engine.display(self.v21,self.v22)
    	engine.display(self.v22,self.v23)
    	engine.display(self.v23,self.v24)
    	engine.display(self.v24,self.v21)

	engine.display(self.vconn1,self.vconn2)
	engine.display(self.vconn3,self.vconn4)
	engine.display(self.vconn5,self.vconn6)
	engine.display(self.vconn7,self.vconn8)
### 3d.engine - 3DS Max file reader
### 
### Copyright (c) 2011-2012 Johan Ceuppens
###
### All rights reserved.
###
### Redistribution and use in source and binary forms, with or without
### modification, are permitted provided that the following conditions
### are met:
### 1. Redistributions of source code must retain the above copyright
###    notice, this list of conditions and the following disclaimer.
### 2. Redistributions in binary form must reproduce the above copyright
###    notice, this list of conditions and the following disclaimer in the
###    documentation and/or other materials provided with the distribution.
### 3. The name of the authors may not be used to endorse or promote products
###    derived from this software without specific prior written permission.
###
### THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
### IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
### OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
### IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
### INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
### NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
### DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
### THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
### (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
### THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Copyright (C) Johan Ceuppens 2011-2012

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import pygame, sys,os
from pygame.locals import *
from string import *
from vector3 import *

class DSFile:
    def __init__(self, dsfilename):
	self.vertices = []
	self.infile = open(dsfilename, 'r')
	self.infile.seek(0)
	self.prevend = 0

    def read(self):
	id = 0
	id = self.infile.read(2)
	id = ord(id[0]) + ord(id[1])
	end = self.infile.read(4)
	end = ord(end[0]) + ord(end[1]) + ord(end[2]) + ord(end[3])
	print "id=%d" % id

	filelen =  self.infile.read(16/8) ### short
	filelen = ord(filelen[0]) + ord(filelen[1])
	print "filelen=%d end=%d" %  (filelen,end)
	for i in range(0, end):###FIX filelen/4):
		str = self.infile.read(64/8) ### NOTE: float is 64 bits long here
		bin = ord(str[0])+ord(str[1])+ord(str[2])+ord(str[3])+ord(str[4])+ord(str[5])+ord(str[6])+ord(str[7])
		if (id == 411):
			print "ord=%f" % bin
			self.vertices.append(bin)

    def display(self,engine):
            engine.setcolor((0,0,255))
	    j = 0
	    for i in range(0,len(self.vertices)/6):
            	v1 = Vector3(self.vertices[j],self.vertices[j+1],self.vertices[j+2])
	    	v2 = Vector3(self.vertices[j+3],self.vertices[j+4],self.vertices[j+5])
	    	engine.display(v1,v2)
	    	j += 6

### 3d.engine
###
### Copyright (c) 2011-2012 Johan Ceuppens
###
### All rights reserved.
###
### Redistribution and use in source and binary forms, with or without
### modification, are permitted provided that the following conditions
### are met:
### 1. Redistributions of source code must retain the above copyright
###    notice, this list of conditions and the following disclaimer.
### 2. Redistributions in binary form must reproduce the above copyright
###    notice, this list of conditions and the following disclaimer in the
###    documentation and/or other materials provided with the distribution.
### 3. The name of the authors may not be used to endorse or promote products
###    derived from this software without specific prior written permission.
###
### THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
### IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
### OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
### IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
### INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
### NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
### DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
### THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
### (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
### THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Copyright (C) Johan Ceuppens 2011

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import pygame, sys,os
from pygame.locals import *
import math
from vector3 import *
from matrix3 import *

class Engine():
    def __init__(self, screen):
	theta1 = self.theta1 = 3.0
	theta2 = self.theta2 = 3.0
	theta3 = self.theta3 = 3.0
	self.mx = Matrix3(1,0,0,
			0,math.cos(theta1),-math.sin(theta1),
			0,math.sin(theta1),math.cos(theta1))
	self.my = Matrix3(math.cos(theta2)/1.0,0, math.sin(theta2)/1.0,
			0,1,0,
			-math.sin(theta2),0, math.cos(theta2))
	self.mz = Matrix3(math.cos(theta3)/1.0, -math.sin(theta3)/1.0, 0,
			math.sin(theta3)/1.0, math.cos(theta3)/1.0, 0,
			0,0,1)
	self.screen = screen
	self.color = (255,255,255)

    def rotate(self, t1,t2,t3):
	self.mx = Matrix3(1,0,0,
			0,math.cos(t1),-math.sin(t1),
			0,math.sin(t1),math.cos(t1))
	self.my = Matrix3(math.cos(t2)/1.0,0, math.sin(t2)/1.0,
			0,1,0,
			-math.sin(t2),0, math.cos(t2))
	self.mz = Matrix3(math.cos(t3)/1.0, -math.sin(t3)/1.0,0.0,
			math.sin(t3)/1.0, math.cos(t3)/1.0, 0.0,
			0.0,0.0,1.0)

#    def drawLine(self, x1,y1,x2,y2):
#	xlen = x2-x1
#	ylen = y2-y1
#	xmod = xlen / (ylen + 1)#Float division with 0
#	ymod = ylen / (xlen + 1)
#	yy = y1
#	if x1<x2:
#	    xx = x1
#	    while xx < x2 or yy < y2:
#	        self.screen.blit(self.surf, (xx, yy))
#	        xx += xmod
#	        yy += ymod
#	else:
#	    xx = x2
#	    while xx < x1 or yy < y2:
#	        self.screen.blit(self.surf, (xx, yy))
#	        xx += xmod
#	        yy += ymod
	    

    def transmit(self, v):
	m = self.mx.multiplyByMatrix(self.my)
	m = m.multiplyByMatrix(self.mz)
	retv = m.multiply(v)
	return retv


    ### NOTES :
    ### this function displays according to the present rot matrices
    def display(self, v1, v2):
	m = self.mx.multiplyByMatrix(self.my)
	m = m.multiplyByMatrix(self.mz)
	retv1 = m.multiply(v1)
	retv2 = m.multiply(v2)
	pygame.draw.line(self.screen, self.color, ## NOTEFIXME 
			(retv1.array[0],retv1.array[1]),
			(retv2.array[0],retv2.array[1]))

    def displayPoly(self, pointlist):
	pygame.draw.polygon(self.screen, self.color, pointlist,0)

    def setcolor(self, c):
	self.color = c
### 3d.engine
###
### Copyright (c) 2011-2012 Johan Ceuppens
###
### All rights reserved.
###
### Redistribution and use in source and binary forms, with or without
### modification, are permitted provided that the following conditions
### are met:
### 1. Redistributions of source code must retain the above copyright
###    notice, this list of conditions and the following disclaimer.
### 2. Redistributions in binary form must reproduce the above copyright
###    notice, this list of conditions and the following disclaimer in the
###    documentation and/or other materials provided with the distribution.
### 3. The name of the authors may not be used to endorse or promote products
###    derived from this software without specific prior written permission.
###
### THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
### IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
### OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
### IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
### INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
### NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
### DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
### THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
### (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
### THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Copyright (C) Johan Ceuppens 2011

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
import pygame, sys,os
from pygame.locals import *
from screen import *

if  __name__ == '__main__' :
    pygame.init()
  
    scr = Screen()
    scr.run()
  
### 3d.engine
###
### Copyright (c) 2011-2012 Johan Ceuppens
###
### All rights reserved.
###
### Redistribution and use in source and binary forms, with or without
### modification, are permitted provided that the following conditions
### are met:
### 1. Redistributions of source code must retain the above copyright
###    notice, this list of conditions and the following disclaimer.
### 2. Redistributions in binary form must reproduce the above copyright
###    notice, this list of conditions and the following disclaimer in the
###    documentation and/or other materials provided with the distribution.
### 3. The name of the authors may not be used to endorse or promote products
###    derived from this software without specific prior written permission.
###
### THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
### IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
### OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
### IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
### INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
### NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
### DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
### THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
### (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
### THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Copyright (C) Johan Ceuppens 2011

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import pygame, sys,os
from pygame.locals import *

from vector3 import *

class Matrix3():
    def __init__(self, xx1,yy1,zz1,xx2,yy2,zz2,xx3,yy3,zz3):
	self.array = [xx1,yy1,zz1,xx2,yy2,zz2,xx3,yy3,zz3]


    def transpose(self):
	m = Matrix3(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0)
	array = [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]
	array[0] = self.array[0]
	array[1] = self.array[3]
	array[2] = self.array[6]
	array[3] = self.array[1]
	array[4] = self.array[4]
	array[5] = self.array[7]
	array[6] = self.array[2]
	array[7] = self.array[5]
	array[8] = self.array[8]
	m.array = array
        return m	

    def multiply(self, v1):
	retv = Vector3(0.0,0.0,0.0)
	for j in [0,1,2]:
	    for i in [0,1,2]:
	        retv.array[i] += self.array[j*3+i] * v1.array[i]
	return retv

    def multiplyByMatrix(self, m1):#FIXME sum
	retm = Matrix3(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0)
	m = m1.transpose()
	for k in [0,1,2,3,4,5,6,7,8]:
	    for j in [0,1,2]:
	        retm.array[k] += self.array[j] * m.array[j]
	return retm
    
### 3d.engine
###
### Copyright (c) 2011-2012 Johan Ceuppens
###
### All rights reserved.
###
### Redistribution and use in source and binary forms, with or without
### modification, are permitted provided that the following conditions
### are met:
### 1. Redistributions of source code must retain the above copyright
###    notice, this list of conditions and the following disclaimer.
### 2. Redistributions in binary form must reproduce the above copyright
###    notice, this list of conditions and the following disclaimer in the
###    documentation and/or other materials provided with the distribution.
### 3. The name of the authors may not be used to endorse or promote products
###    derived from this software without specific prior written permission.
###
### THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
### IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
### OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
### IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
### INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
### NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
### DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
### THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
### (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
### THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Copyright (C) Johan Ceuppens 2011-2012

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import pygame, sys,os
from pygame.locals import *

from vector3 import *
from cube import *

class Room1():
    def __init__(self):

	self.cubes = []
	self.cubes.append(Cube(0,0,0))
	self.cubes.append(Cube(20,20,0))
	self.cubes.append(Cube(100,200,0))

    def rotate(self,engine,rx,ry,rz):
	for cube in self.cubes:
	    cube.rotate(engine,rx,ry,rz)

    def transpose(self):
	1

    def display(self,engine):
	engine.setcolor((0,0,255))
	engine.display(Vector3(0,0,0),Vector3(100,100,0))
	engine.display(Vector3(0,0,100),Vector3(100,100,100))
        ###FIXengine.rotate(.3,1,1)
	v1 = engine.transmit(
	Vector3(0,0,0))
	v2 = engine.transmit(
	Vector3(100,100,0))
	v3 = engine.transmit(
	Vector3(0,0,100))
	v4 = engine.transmit(
	Vector3(100,100,0))
	engine.displayPoly([(v1.array[0],v1.array[1]),(v2.array[0],v2.array[1]),(v3.array[0],v3.array[1]),(v4.array[0],v4.array[1])])

	engine.setcolor((0,0,240))
	for cube in self.cubes:
		cube.display(engine)
	
### 3d.engine
###
### Copyright (c) 2011-2012 Johan Ceuppens
###
### All rights reserved.
###
### Redistribution and use in source and binary forms, with or without
### modification, are permitted provided that the following conditions
### are met:
### 1. Redistributions of source code must retain the above copyright
###    notice, this list of conditions and the following disclaimer.
### 2. Redistributions in binary form must reproduce the above copyright
###    notice, this list of conditions and the following disclaimer in the
###    documentation and/or other materials provided with the distribution.
### 3. The name of the authors may not be used to endorse or promote products
###    derived from this software without specific prior written permission.
###
### THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
### IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
### OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
### IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
### INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
### NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
### DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
### THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
### (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
### THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Copyright (C) Johan Ceuppens 2011

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import pygame, sys,os
import pygame, sys,os
from pygame.locals import *
from engine import *
from dsfile import *
from room1 import *
from string import *

class Screen():
    def __init__(self):
        self.window = pygame.display.set_mode((800, 600))
    	self.dsf = DSFile("./example.3ds")

	for i in range(0,30000):
    		self.dsf.read()###FIXME FIX multiple reads 1000 should be EOF of .3ds file	
	pygame.font.init()
        self.screen = pygame.display.get_surface()
        self.screenwidth = 800
        self.screenheight = 600
#	self.font = pygame.font.SysFont("Vera", 16)
        
        self.clock = pygame.time.Clock() 

	self.counter = 1

	self.transx = 1
	self.transy = 1

    def run(self):
        run = 1
        
        while run:
        
#            self.screen.fill(0, None, 0)

            event = pygame.event.poll()#get()
	    if 1:
               if event.type == QUIT or (event.type == KEYDOWN and 
                                         event.key in [K_ESCAPE, K_q]):
                   run = 0
               ###moving
	       key = pygame.key.get_pressed()
	
	       if key[pygame.K_LEFT] and self.map.offsetx < 0:
                   self.player.move_left()
	       elif key[pygame.K_RIGHT]:
                   self.player.move_right()
	       elif key[pygame.K_UP]:
                   self.player.jump()
		   self.player.totalcounter = 27+self.player.jumpcounter
	       elif key[pygame.K_DOWN]:
                   self.player.move_down()

	   # self.counter += 1
	    self.transx += 2
	    self.transy += 2
###	    self.engine.rotate(self.transx,self.transx,3)
###	    self.v1 = self.engine.display(self.engine.mx,self.engine.my)


            engine = Engine(self.screen)


#            v1 = Vector3(10.0,10.0,0.0)
#            v2 = Vector3(20.0,10.0,0.0)
#            v3 = Vector3(20.0,20.0,0.0)
#            v4 = Vector3(10.0,20.0,0.0)
#	    v1 = engine.display(v1,v2)
#	    v2 = engine.display(engine.my,engine.mz)
#	    v2 = engine.display(v2,v3)
#	    v3 = engine.display(engine.mz,engine.mz)
#	    v3 = engine.display(v3,v4)
#	    v4 = engine.display(v4,v1)
#	    engine.display(v1,v2)
#	    engine.display(v2,v3)
#	    engine.display(v3,v4)
#	    engine.display(v4,v1)

			
#            cube = Cube(0,0,0)
#	    cube.display(engine)
            room = Room1()
#	    room.rotate(engine,2,2,2)
            room.display(engine)
            self.dsf.display(engine)
            pygame.display.flip()
           

            self.clock.tick(18)



### 3d.engine
###
### Copyright (c) 2011-2012 Johan Ceuppens
###
### All rights reserved.
###
### Redistribution and use in source and binary forms, with or without
### modification, are permitted provided that the following conditions
### are met:
### 1. Redistributions of source code must retain the above copyright
###    notice, this list of conditions and the following disclaimer.
### 2. Redistributions in binary form must reproduce the above copyright
###    notice, this list of conditions and the following disclaimer in the
###    documentation and/or other materials provided with the distribution.
### 3. The name of the authors may not be used to endorse or promote products
###    derived from this software without specific prior written permission.
###
### THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
### IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
### OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
### IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
### INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
### NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
### DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
### THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
### (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
### THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Copyright (C) Johan Ceuppens 2011

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
import pygame, sys,os
from pygame.locals import *



class Vector3():
    def __init__(self, xx,yy,zz):
	self.array = [xx,yy,zz]
	
    def multiply(self, v1):
	retv = Vector3(1.0,1.0,1.0) 
	for i in [0,1,2]:
	    retv.array[i] = self.array[i] * v1[i]
	return retv

    def dotp(self, v1):
	ret = 0.0
	for i in [0,1,2]:
	    ret += self.array[i] * v1[i]
	return ret


\end{verbatim}
\end{mylisting}


\section{\large Conclusion}


\bibliographystyle{plain}
\bibliography{refs} % refs.bib

\end{document}


